import { 
  getItineraryInfoByIdForUser,//我的行程详情
  getItineraryInfoById,//推薦行程详情
} from '../../api/home'
import { imageURL } from '../../../utils/request'

Page({
  data: {
    imageURL:'',
    carouselImages: [
      '/pages/assets/image/motianlun.jpg',
      '/pages/assets/image/motianlun.jpg',
      '/pages/assets/image/motianlun.jpg'
    ],
    longitude: 116.404,  // 默認北京中心坐標
    latitude: 39.915,
    showInfoCard: false,
    currentDayIndex: 0,
    markers: [],
    selectedMarker: null,
    itineraryDetail:{},
  },

  async onLoad(e) {
    if(e.type=='my'){
      const res = await getItineraryInfoByIdForUser({
        itinerary_id:e.itinerary_id
      })
      this.setData({
        itineraryDetail:res.data,
        imageURL
      })
    }else{
      const res = await getItineraryInfoById({
        itinerary_id:e.itinerary_id
      })
      this.setData({
        itineraryDetail:res.data,
        imageURL
      })
    }
    this.getLocation();
  },
  onPreviewImage(e) {
    const index = e.currentTarget.dataset.index;
    wx.previewImage({
      current: this.data.carouselImages[index],
      urls: this.data.carouselImages
    });
  },
  // 獲取用戶位置
  getLocation() {
    wx.getLocation({
      type: 'gcj02',
      success: (res) => {
        
      },
      fail: () => {
        wx.showToast({ title: '獲取位置失敗', icon: 'none' });
      }
    });
  },

  // 地圖區域變化
  onRegionChange(e) {
    console.log('地圖移動', e);
  },

  // 回到當前位置
  // moveToLocation() {
  //   const mapCtx = wx.createMapContext('myMap');
  //   mapCtx.moveToLocation();
  // },
  toggleInfoCard() {
    this.setData({ showInfoCard: !this.data.showInfoCard });
  },

  switchDay(e) {
    const index = e.currentTarget.dataset.index;
    this.setData({ currentDayIndex: index });
  },
  goDetails(e){
    const place_id = e.currentTarget.dataset.place_id
    wx.navigateTo({
      url: `/pages/Itinerary/SceneryDetails/SceneryDetails?place_id=${place_id}`,
    })
  },

});